package com.example.mvvm

import android.util.Log
import android.view.View
import androidx.databinding.Observable
import androidx.databinding.ObservableField
import androidx.databinding.ObservableInt
import com.atom.module.mvvm.adapter.ClickEvent
import com.atom.module.mvvm.adapter.VisitEvent
import com.atom.module.mvvm.base.AbstractBaseViewModel
import com.atom.module.mvvm.base.AbstractViewModel
import com.atom.module.mvvm.base.EmptyModel
import com.atom.module.mvvm.base.IModel
import com.atom.module.mvvm.livedata.SingleLiveData
import com.example.mvvm.pokemon.ui.list.ListActivity

class MainViewModel : AbstractBaseViewModel<IModel>(EmptyModel) {

    val hello: ObservableField<String> = ObservableField("asdasdasdasd")

    val skipListActivity = object : SingleLiveData<View>(){}

    val event2 = object : ClickEvent<Unit>() {
        override fun invoke(t: View) {
            Log.e("MainViewModel", "aa2 > ${System.currentTimeMillis()}  ${t.id}")
        }
    }.also {
        it.addOnPropertyChangedCallback(object : Observable.OnPropertyChangedCallback() {
            override fun onPropertyChanged(sender: Observable?, propertyId: Int) {
                Log.e("MainViewModel", " ${sender}  ${propertyId}  ")
            }
        })
    }

    val show = VisitEvent(View.GONE).also {
        it.addOnPropertyChangedCallback(object : Observable.OnPropertyChangedCallback() {
            override fun onPropertyChanged(sender: Observable?, propertyId: Int) {
                if (sender is ObservableInt) {
                    Log.e("MainViewModel", " ${sender}  ${propertyId}  ${sender.get()}")
                }
            }
        })
    }

    fun aa() {
        hello.set("asdad");
    }

    fun aa2(v: View) {
        Log.e("MainViewModel", "aa2 > ${System.currentTimeMillis()}")
        hello.set("asdad");
        //startActivity(PokeMainActivity::class.java)
        startActivity(ListActivity::class.java)
    }

    fun aa3() {
        if (show.get() != View.GONE) {
            show.set(View.GONE)
        } else {
            show.set(View.VISIBLE)
        }
    }
}